<template>
  <div>
    <div style="background-color: #F5F5F5;">
      <el-row style="width: 80%;margin: 0 auto">
        <el-col :span="12" style="margin-top: 5px;margin-bottom: 5px">
          <div v-if=!adminname style="float: left">
            <el-link :underline="false" @click="login">登录</el-link>
            <el-divider direction="vertical"></el-divider>
            <el-link :underline="false" href="/register">注册</el-link>
            <el-divider direction="vertical"></el-divider>
            <el-link :underline="false" href="/adminLogin">商家登录</el-link>
          </div>
          <div v-else style="float: left">
            <el-dropdown>
              <span class="el-dropdown-link">
                <el-link :underline="false" href="/person">{{ adminname }}</el-link> <i
                  class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item style="width: 120px;height: 30px">
                    <el-link :underline="false" @click="logout"
                             style="align-items: center;display: flex;justify-content: center">退出登录
                    </el-link>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            <el-divider direction="vertical"></el-divider>

          </div>
        </el-col>
        <el-col :span="12" style="margin-top: 5px;margin-bottom: 5px">
          <div style="float: right">
            <el-link :underline="false" href="/">商城首页</el-link>
          </div>
        </el-col>
      </el-row>
    </div>
    <div>
      <el-row style="width: 80%;margin: 0 auto">
        <el-col :span="6" style="margin-top: 5px;margin-bottom: 5px">
          <el-link href="/admin" style="float: left" :underline="false">
            <img src="../assets/logo.png" width="130px"/>
          </el-link>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import router from "@/router";

export default {
  name: "AdminNavi",
  data() {
    return {
      adminname: localStorage.getItem("adminname"),
      adminId: localStorage.getItem("adminId")
    };
  },
  methods: {
    logout() {
      localStorage.removeItem("adminname")
      sessionStorage.removeItem("admintoken")
      localStorage.removeItem("adminId")
      this.$message.success("退出成功")
      this.adminname = ""
      this.$router.push("/adminLogin")
    },
    login() {
      router.push({
        path: '/adminLogin',
        query: {
          redirect: router.currentRoute.fullPath  // 防止从外部进来登录
        }
      })
    }
  }
}
</script>

<style scoped>

</style>